﻿Imports Oracle.DataAccess.Client
Public Enum eTipoTercero

    Proveedor = 1
    Cliente = 2
    Empleado = 3
End Enum

Public Class cTercero

    Private lDrTercero As dsTercero.TER_TERCERORow
    Private lICliente As cClientes
    Private lIVendedor As cVendedor
    Private lIProveedor As cProveedores
    Private lIMunicipios As cMunicipios
    Private lExiste As Boolean
    Sub New(ByVal idTercero As String, ByVal TipoTer As String)
        Try
            Dim daTer As New dsTerceroTableAdapters.TER_TERCEROTableAdapter
            Dim dtTer As dsTercero.TER_TERCERODataTable = daTer.GetDataByIdTercero(idTercero)
            If dtTer.Rows.Count > 0 Then
                lDrTercero = dtTer.Rows(0)
                lExiste = True
                Select Case TipoTer
                    Case "Cli"
                        lICliente = New cClientes(idTercero)
                    Case "Ven"
                        lIVendedor = New cVendedor(idTercero)
                    Case "Pro"
                        lIProveedor = New cProveedores(idTercero)
                End Select
                lIMunicipios = New cMunicipios(lDrTercero.IDMUNICIPIO)
            Else
                lExiste = False
            End If
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        End Try
    End Sub

    Public ReadOnly Property Existe() As Boolean
        Get
            Return lExiste
        End Get
    End Property
    Public ReadOnly Property TipoDocIden() As eTipoDocTercero
        Get
            Return lDrTercero.DOCIDENT
        End Get
    End Property

    Public ReadOnly Property DocIdent() As String
        Get
            Return lDrTercero.DOCIDENT
        End Get
    End Property
    Public ReadOnly Property NombreCompleto() As String
        Get
            Return lDrTercero.NOMBRES + " " + lDrTercero.APELLIDOS
        End Get
    End Property
    Public ReadOnly Property Nombres() As String
        Get
            Return lDrTercero.NOMBRES
        End Get
    End Property

    Public ReadOnly Property Apellidos() As String
        Get
            Return lDrTercero.APELLIDOS
        End Get
    End Property

    Public ReadOnly Property Direccion() As String
        Get
            Return lDrTercero.DIRECCION
        End Get
    End Property

    Public ReadOnly Property Telefono() As String
        Get
            Return lDrTercero.TELEFONO
        End Get
    End Property

    Public ReadOnly Property idMunicipio() As String
        Get
            Return lDrTercero.IDMUNICIPIO
        End Get
    End Property

    Public ReadOnly Property Estado() As Int16
        Get
            Return lDrTercero.ESTADO
        End Get
    End Property

    Public ReadOnly Property RazonSocial() As String
        Get
            Return lDrTercero.RAZONSOCIAL
        End Get
    End Property

    Public ReadOnly Property iClientes() As cClientes
        Get
            Return lICliente
        End Get
    End Property

    Public ReadOnly Property iVendedor() As cVendedor
        Get
            Return lIVendedor
        End Get
    End Property

    Public ReadOnly Property iProveedor() As cProveedores
        Get
            Return lIProveedor
        End Get
    End Property

    Public ReadOnly Property iMunicipios() As cMunicipios
        Get
            Return lIMunicipios
        End Get
    End Property
    Protected Overrides Sub Finalize()
        lIProveedor = Nothing
        lIVendedor = Nothing
        lICliente = Nothing
        lDrTercero = Nothing
        lIMunicipios = Nothing
    End Sub


End Class

Public Enum eTipoDocTercero
    Nit = 1
    Cedula = 2
    TarjetaIdent = 3
End Enum


Public Class DatosTerceros
    Public Shared Function GetClientes() As DataSet
        Using conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
            Using cmd As OracleCommand = conn.CreateCommand
                cmd.CommandText = "SELECT * FROM TER_VCLIENTES"
                Try
                    Dim dsCli As New DataSet
                    Dim dtCli As New DataTable
                    conn.Open()
                    dtCli.Load(cmd.ExecuteReader)
                    conn.Close()
                    dsCli.Tables.Add(dtCli)
                    Return dsCli
                Catch ex As Exception
                    Throw ex
                End Try
            End Using
        End Using
    End Function

    Public Shared Function GetVendedores() As DataSet
        Using conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
            Using cmd As OracleCommand = conn.CreateCommand
                cmd.CommandText = "SELECT * FROM TER_VVENDEDORES"
                Try
                    Dim dsVen As New DataSet
                    Dim dtVen As New DataTable
                    conn.Open()
                    dtVen.Load(cmd.ExecuteReader)
                    conn.Close()
                    dsVen.Tables.Add(dtVen)
                    Return dsVen
                Catch ex As Exception
                    Throw ex
                End Try
            End Using
        End Using
    End Function

    Public Shared Function GetProveedores() As DataSet
        Using conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
            Using cmd As OracleCommand = conn.CreateCommand
                cmd.CommandText = "SELECT * FROM TER_VPROVEEDORES"
                Try
                    Dim dsPro As New DataSet
                    Dim dtPro As New DataTable
                    conn.Open()
                    dtPro.Load(cmd.ExecuteReader)
                    conn.Close()
                    dsPro.Tables.Add(dtPro)
                    Return dsPro
                Catch ex As Exception
                    Throw ex
                End Try
            End Using
        End Using
    End Function

End Class